home *** CD-ROM | disk | FTP | other *** search
- # Dispatcher Error Title
- $TITLE="Catalog Maker Dispatch Error";
- ###############################
- # END OF CHANGEABLE OPTIONS #
- ###############################
-
- # START MAIN PROGRAM
- # ------------------
-
- &ReadParse;
- $Session = $in{'SessionID'};
- if ($Session eq '') {&GetSession;} # Get a session id
- elsif ($Session eq '*SeSiOnId*') {&GetSession;}; # Get a session id
-
- $targetFile = $ENV{'PATH_TRANSLATED'};
- $ItemID = $in{'ItemID'};
-
- $Debug=$in{'Debug'};
- if ($Debug eq 'True') {
- print "Content-Type: text/html\n\n";
- print "<HTML><HEAD><TITLE>Debug Info</TITLE></HEAD><BODY>";
- print "Session=$Session<br>";
- print "Target =$targetFile<br>";
- print "</BODY></HTML>";
- } # debug info
-
- print "Content-Type: text/html\n\n";
-
- print (&ReplaceState($targetFile, "SessionID=$Session")); # send the info ..
-
- exit(1);
-
- # GENERAL SUBROUTINES
- # -------------------
-
- sub ReadParse {
- local (*in) = @_ if @_; local ($i, $loc, $key, $val);
- if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; }
- elsif ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); }
- @in = split(/&/,$in);
- foreach $i (0 .. $#in) {
- $in[$i] =~ s/\+/ /g;
- ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
- $key =~ s/%(..)/pack("c",hex($1))/ge;
- $val =~ s/%(..)/pack("c",hex($1))/ge;
- $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
- $in{$key} .= $val;
- }
- return 1; # just for fun
- } # ReadParse
-
- sub GetSession {
- $Session = $$; # use the current PID as the new session id,
- # we might change this later to a cyclic queue to ensure that
- # a speicified # of customers can access the site at once.
- &StartSession($Session); # StartSession is generated by CatMake
- } # GetSession
-
- sub ReplaceState {
- local($fileName, $state) = @_;
-
- open(INPUT, "<$fileName") || "Error opening URL.\n";
-
- undef $/; # Read in the entire file
- ($data = <INPUT>) || "Error reading file.\n";
-
- $data =~ s/\*SeSiOnId\*/$Session/g;
-
- # while ($data =~ /SessionID=\*SeSiOnId\*/) {
- # } # find the replaceables ..
-
- if (!dbmopen(%subs, "items", 0777)) {
- "Can not read items database";
- exit 1;
- }
-
- if (!dbmopen(%items, "$Session", 0777)) {
- "Error opening the session data";
- exit 1;
- }
-
- $subItems = $subs{$ItemID};
- if ($subItems != "") {
- for ( $si = 1; $si <= $subItems; $si++ ) {
- $TheSubItem = $ItemID . $si;
- $TheValue = $items{$TheSubItem};
- $data =~ s/\*$TheSubItem\*/$TheValue/g;
- } # for
- } # there are sub items
-
- dbmclose(%items);
- dbmclose(%subs);
-
- $data; # return the file
-
- } # ReplaceSession
-
-
- sub PrintError {
- print("Content-Type: text/html\n\n");
- print <<EOF;
- <HTML>
- <HEAD><TITLE>ERROR</TITLE></HEAD>
- <BODY>
- <H1 ALIGN=CENTER>$TITLE</H1> <HR>
- An error occured in the script!
- <HR>
- EOF
- } # PrintError
-
- sub PrintSuccess {
- print <<EOF;
- <HTML>
- <HEAD><TITLE>Success</TITLE></HEAD>
- <BODY>
- <H1 ALIGN=CENTER>$TITLE</H1> <HR>
- Your request was processed succesfuly!
- Thank you for using a catalog maker product!
- <HR>
- EOF
- } # PrintSuccess
-
-